package com.lemonfish.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lemonfish.mapper.GoodsMapper;
import com.lemonfish.pojo.entity.Goods;
import com.lemonfish.service.GoodsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 商品相关Service实现
 *
 * @author Lemonfish
 * @version 1.0
 * @date 2020-03-11
 * Copyright © Chao Zhang
 */
@Service
@Slf4j
public class GoodsServiceImpl extends BaseCustomServiceImpl<GoodsMapper, Goods> implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;

    @Override
    public IPage<Goods> getGoodsList(long curPage, long size, String order, String column) {
        QueryWrapper<Goods> queryWra = new QueryWrapper<>();

        if ("descending".equals(order)) {
            queryWra.orderByDesc(column);
        } else {
            queryWra.orderByAsc(column);
        }

        return goodsMapper.selectPage(new Page<Goods>(curPage, size), queryWra);
    }
}
